package co.edu.unal.bioingenium.kbmed.knowledge.mapping.vo;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 *
 * @author lariverosc
 */
public class DescriptorScoresMap {

    /**
     * Ordered list of sentence words
     */
    private List<String> sentenceWords;
    /**
     * Map that contains the descriptors scores <descriptorId, DescriptorScore>
     */
    private Map<String, DescriptorScore> map;
    /**
     * Array that contains the max scores for each word in the sentence
     */
    private double maxScores[];

    private DescriptorScoresMap() {
    }

    /**
     * 
     * @param sentenceWords 
     */
    public DescriptorScoresMap(List<String> sentenceWords) {
        this.sentenceWords = sentenceWords;
        map = new HashMap<String, DescriptorScore>();
        maxScores = new double[sentenceWords.size()];
        Arrays.fill(maxScores, 0);
    }

    /**
     * 
     * @return
     */
    public List<String> getSentence() {
        return sentenceWords;
    }

    /**
     * 
     * @param sentence
     */
    public void setSentence(List<String> sentence) {
        this.sentenceWords = sentence;
    }

    /**
     * 
     * @param descriptorId 
     * @return
     */
    public DescriptorScore getDescriptorScore(String descriptorId) {
        return map.get(descriptorId);
    }

    /**
     * 
     * @return
     */
    public Set<String> keySet() {
        return map.keySet();
    }

    /**
     * 
     * @param map
     */
    public void setMap(Map<String, DescriptorScore> map) {
        this.map = map;
    }

    /**
     * 
     * @param wordSentencePosition 
     * @param descriptorId
     * @param similarity  
     */
    public void setDetailedScore(int wordSentencePosition, String descriptorId, double similarity) {
        if (map.containsKey(descriptorId)) {
            map.get(descriptorId).setScore(wordSentencePosition, similarity);

        } else {
            DescriptorScore tempConceptScore = new DescriptorScore(sentenceWords.size());
            tempConceptScore.setScore(wordSentencePosition, similarity);
            map.put(descriptorId, tempConceptScore);
        }
        if (maxScores[wordSentencePosition] < similarity) {
            maxScores[wordSentencePosition] = similarity;
        }
    }

    /**
     * 
     * @param descriptorId
     * @return
     */
    public double[] getDetailedScore(String descriptorId) {
        if (map.containsKey(descriptorId)) {
            return map.get(descriptorId).getScores();
        }
        return null;
    }

    /**
     * 
     * @param descriptorId
     * @param score
     */
    public void setTotalScore(String descriptorId, double score) {
        if (map.containsKey(descriptorId)) {
            map.get(descriptorId).setTotalScore(score);
        } else {
            DescriptorScore tempConceptScore = new DescriptorScore(sentenceWords.size());
            tempConceptScore.setTotalScore(score);
            map.put(descriptorId, tempConceptScore);
        }
    }

    /**
     * 
     * @param descriptorId
     * @return
     */
    public double getTotalScore(String descriptorId) {
        if (map.containsKey(descriptorId)) {
            return map.get(descriptorId).getTotalScore();
        }
        return 0;
    }

    /**
     * 
     * @return
     */
    public double[] getMaxScores() {
        return maxScores;
    }

    /**
     * 
     * @param maxScores
     */
    public void setMaxScores(double[] maxScores) {
        this.maxScores = maxScores;
    }
}
